package com.iris.nio;

import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.nio.channels.CompletionHandler;
import java.util.concurrent.ExecutionException;

public class AioAcceptHandler implements CompletionHandler<AsynchronousSocketChannel, AioAttach> {
    @Override
    public void completed(AsynchronousSocketChannel result, AioAttach attachment) {
//        result.write();
        try {
            System.out.println("completed:"+attachment.getId());
            result.write(ByteBuffer.wrap("welcome111:".getBytes())).get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void failed(Throwable exc, AioAttach attachment) {

        System.out.println("failed");
    }
}
